<?php

class ad extends adminBase{
    function  __construct(){
        parent::__construct();
        $this->cms->setPageTitle("广告管理");
        $this->cms->setControlFile("admin/tpl/ad/ad_control.json");
        $admin_info=$this->user->getLoginInfo();
        $user=UserMode::init();
        $levels=$user->getLevels($admin_info['id']);
        if(!$user->checkLevels(15,$levels)){
            $r['message']="您不具有此权限！";
            View::displayAsHtml($r,"plugin/state/tips.php");
            exit();
        }
    }

    function indexTask($page=1,$user_tel){
        $ad = AdMode::init();
        $url=WebRouter::init()->getQuestion("page=");
        $page=$page>=1? $page: 1;
        $countOfPage=10;
        $offset=($page-1)*$countOfPage;
        list($r['list'],$total)=$ad->getList($countOfPage,$offset);
         $r['page']=new Page($page,$total,$countOfPage);
        $r['page']->setPageCallback(create_function('$page','return "'.$url.'".$page;'));
        $this->cms->tableScene($r,"admin/tpl/ad/ad.php");
    }

    function addTask(){
        $this->cms->setActionTitle("添加广告");
        $this->cms->formScene(array(),"admin/tpl/ad/ad_add.php");
    }

    function addSubmitTask($url){
        $up=Uploader::init();
        $pic=PictureModule::init("picture");
        $ad=AdMode::init();
        $picArray=array( array('set'=>"goods","width"=>1028,'height'=>430));
        list($stateInfo,$picDataArray)=$up->upImage('file',null,$picArray);
        if(strtolower($stateInfo)=='success'){
            $pic_id=$pic->add($picDataArray['goods']['url'],$picDataArray['goods']['savePath'],$picDataArray['goods']['filename']);
            if($ad->add($pic_id,$url,null,null)){
                $r['url']=WebRouter::init()->getAction("index");
                $r['message']="图片添加成功";
            }else{
                $r['message']="图片添加失败";
            }
        }else{
            $r['message']="图片添加失败";
        }
        View::displayAsHtml($r, "plugin/state/tips.php");
    }

    function deleteTask($id){
        $ad = AdMode::init();
        if($ad->delete($id)){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="图片删除成功";
        }else{
            $r['message']="图片删除失败";
        }
        View::displayAsHtml($r, "plugin/state/tips.php");
    }
} 